package com.dlc.shop.listener;


import com.dlc.shop.bean.event.UserDataEvent;
import com.dlc.shop.bean.order.UserDataOrder;
import com.dlc.shop.bean.param.UserManagerParam;
import com.dlc.shop.service.OrderDataAnalysisService;
import com.dlc.shop.service.OrderRefundService;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.event.EventListener;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Component;


/**
 * 统计一下用户的信息
 * @author yami
 */
@Slf4j
@Component("defaultUserDataListener")
@AllArgsConstructor
public class UserDataListener {


    private final OrderDataAnalysisService orderDataAnalysisService;
    private final OrderRefundService orderRefundService;

    @EventListener(UserDataEvent.class)
    @Order(UserDataOrder.DEFAULT)
    public void userReceiptOrderLister(UserDataEvent event) {
        UserManagerParam param = event.getUserManagerParam();
        // 最近消费时间 消费金额 实付金额 消费次数 平均折扣
        orderDataAnalysisService.getConsumeData(param);
        // 售后金额  售后次数
        orderRefundService.getRefundDataByUserId(param);
        // 实付金额, 累计支付的金额: 除了余额支付/积分支付的订单累计金额 + 余额充值金额
    }
}
